﻿
var model = function() {
    return {
        PortalGroups: [{ PortalGroupId: 1, MasterPortal: { PortalId: 1, PortalName: "PortalOne" }, PortalGroupName: "Group1", AuthenticationDomain: "Domain1", Portals: [] },
            {
                PortalGroupId: 2,
                MasterPortal: { PortalId: 2, PortalName: "PortalTwo" },
                PortalGroupName: "Group2",
                AuthenticationDomain: "Domain2",
                Portals:
                    [{ PortalId: 5, PortalName: "PortalFive" }, { PortalId: 6, PortalName: "PortalSix" }]
            }],
        AvailablePortals: [{ PortalId: 3, PortalName: "PortalThree" }, { PortalId: 1, PortalName: "PortalFour" }]
    };
};
var model_with_only_one_available_portal = function () {
    return {
        AvailablePortals: [{ PortalId: 1, PortalName: "PortalOne" }]
    };
};


test("localize is working", function () {
    var localization = { a: 'a' };
    var vm = new dnneurope.portalgroups.ViewModel(model, localization);
    ok(vm.localize.a == 'a', "Localization is working");
});

test("Add Portal to Group", function () {
    //arrange
    var vm = new dnneurope.portalgroups.ViewModel(model());
    var group = vm.PortalGroups()[0];
    vm.SelectedPortal(vm.AvailablePortals()[0]);
    var countPortalsInGroup = group.Portals().length;
    var countAvailablePortals = vm.AvailablePortals().length;
    //act
    vm.addPortalToGroup(group);
    //assert
    equal(group.Portals().length, countPortalsInGroup + 1, "Portal was added to group");
    equal(vm.AvailablePortals().length, countAvailablePortals - 1, "Portal was removed from available Portals");
});

test("CreatePortalGroup", function () {
    //arrange
    var vm = new dnneurope.portalgroups.ViewModel(
        model_with_only_one_available_portal(),
        { newPortalGroupPrefix: "Group for " });
    vm.SelectedPortal(vm.AvailablePortals()[0]);
    //act
    vm.addPortalGroup();
    //assert
    equal(vm.PortalGroups().length , 1, "Portal was added to group");
    equal(vm.AvailablePortals().length, 0, "Portal was removed from available Portals");
});
